import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    list: [],
    bannerList: [],
    total: 0,
    classifyList: [],
  },
  mutations: {
    setList(state, payload) {
      state.list = payload.list;
      state.bannerList = payload.banner;
      state.total = payload.total;
    },
    setTabs(state, payload) {
      state.classifyList = payload;
    },
    setMoreList(state, payload) {
      state.list.push(...payload);
    },
  },
  actions: {
    async getList(vuex) {
      // axios.get('/api/list').then(res => {
      // })
      const res = await axios.get("/api/list");
      vuex.commit("setList", res.data);
    },
    async getTabs(vuex) {
      const res = await axios.get("/api/tabs");
      vuex.commit("setTabs", res.data.classifyList);
    },
    async loadMore(vuex) {
      const res = await axios.get("/api/list");
      console.log(res, "res-----");
      vuex.commit("setMoreList", res.data.list);
    },
  },
  modules: {},
});
